home *** CD-ROM | disk | FTP | other *** search
-
- // Copyright (C) 2002 by Luigi Pino. All Rights Reserved.
-
- /***************************************************************************/
-
- #include "../library/neurosis.h"
- #include "draw.h"
- #include "file_io.h"
- #include "hiscore.h"
- #include "initialize.h"
- #include "main.h"
- #include "menu_misc.h"
- #include "paddle.h"
- #include "sphere.h"
- #include "update.h"
-
- /***************************************************************************/
-
- extern High_Score_Struct high_score_sphere;
- extern High_Score_Struct high_score_time;
- extern Paddle_Struct paddle_object[];
- extern Window_Class window;
-
- extern char high_score_name[];
-
- /***************************************************************************/
-
- int Compare_High_Score_Sphere(const void *p, const void *q)
-
- {
- int *p1 = (int*)(p);
- int *q1 = (int*)(q);
-
- if (high_score_sphere.spheres[*p1] < high_score_sphere.spheres[*q1])
- return (-1);
- else if (high_score_sphere.spheres[*p1] > high_score_sphere.spheres[*q1])
- return (1);
- else
- {
- if (high_score_sphere.time[*p1] < high_score_sphere.time[*q1])
- return (1);
- else if (high_score_sphere.time[*p1] > high_score_sphere.time[*q1])
- return (-1);
- else
- return (0);
- }
- }
-
- /***************************************************************************/
-
- int Compare_High_Score_Time(const void *p, const void *q)
-
- {
- int *p1 = (int*)(p);
- int *q1 = (int*)(q);
-
- if (high_score_time.time[*p1] < high_score_time.time[*q1])
- return (1);
- else if (high_score_time.time[*p1] > high_score_time.time[*q1])
- return (-1);
- else
- {
- if (high_score_time.spheres[*p1] < high_score_time.spheres[*q1])
- return (-1);
- else if (high_score_time.spheres[*p1] > high_score_time.spheres[*q1])
- return (1);
- else
- return (0);
- }
- }
-
- /***************************************************************************/
-
- void Save_High_Score_Verification()
-
- {
- bool save_high_score = false;
- FILE *stream;
- int x1;
-
- stream = fopen("hiscore.dat", "a");
-
- for (x1=0;x1<5;x1=x1+1)
- {
- if ((high_score_sphere.new_high[x1] == true) || (high_score_time.new_high[x1] == true))
- save_high_score = true;
- }
-
- if (save_high_score == true)
- {
- fprintf(stream, "%s=%.2f=%.2f=%.2f=%.2f=%.2f\n", high_score_name, paddle_object[Compete].score,
- paddle_object[Compete].time_lapse_score,
- paddle_object[Compete].score * paddle_object[Compete].time_lapse_score * 230.0f,
- paddle_object[Compete].score * paddle_object[Compete].time_lapse_score * 320.0f,
- paddle_object[Compete].score / paddle_object[Compete].time_lapse_score,
- paddle_object[Compete].time_lapse_score / paddle_object[Compete].score);
- }
-
- fclose(stream);
- }
-
- /***************************************************************************/
-
- void Show_High_Scores(bool color_menu)
-
- {
- float y_position = -60.0f;
- int x1;
-
- window.Font_Char(" SECONDS", -265.0f, -20.0f, 10.0f, R_1, G_1, B_1);
- window.Font_Char("SPHERES IN", -265.0f, -30.0f, 10.0f, R_1, G_1, B_1);
- window.Font_Char("ALLOWED BETWEEN", -265.0f, -40.0f, 10.0f, R_1, G_1, B_1);
-
- window.Font_Char(" SECONDS", -265.0f, -20.0f, 10.0f, R_7, G_7, B_7);
- window.Font_Char(" IN SPHERES", -265.0f, -30.0f, 10.0f, R_7, G_7, B_7);
- window.Font_Char(" BETWEEN ALLOWED", -265.0f, -40.0f, 10.0f, R_7, G_7, B_7);
- window.Font_Char("------------------ ------------------", -265.0f, -50.0f, 10.0f, R_1, G_1, B_1);
-
- for (x1=0;x1<5;x1=x1+1)
- {
- if ((high_score_sphere.new_high[x1] == true) && (color_menu == true))
- {
- window.Font_Int(high_score_sphere.spheres[x1], -255.0f, y_position, 10.0f, R_8, G_8, B_8);
- window.Font_Float(high_score_sphere.time[x1], 2, -198.0f, y_position, 10.0f, R_8, G_8, B_8);
- window.Font_Char(high_score_sphere.name[x1], -130.0f, y_position, 10.0f, R_8, G_8, B_8);
- }
- else
- {
- window.Font_Int(high_score_sphere.spheres[x1], -255.0f, y_position, 10.0f, R_1, G_1, B_1);
- window.Font_Float(high_score_sphere.time[x1], 2, -198.0f, y_position, 10.0f, R_7, G_7, B_7);
- window.Font_Char(high_score_sphere.name[x1], -130.0f, y_position, 10.0f, R_7, G_7, B_7);
- }
-
- if ((high_score_time.new_high[x1] == true) && (color_menu == true))
- {
- window.Font_Float(high_score_time.time[x1], 2, 12.0f, y_position, 10.0f, R_8, G_8, B_8);
- window.Font_Int(high_score_time.spheres[x1], 88.0f, y_position, 10.0f, R_8, G_8, B_8);
- window.Font_Char(high_score_time.name[x1], 145.0f, y_position, 10.0f, R_8, G_8, B_8);
- }
- else
- {
- window.Font_Float(high_score_time.time[x1], 2, 12.0f, y_position, 10.0f, R_1, G_1, B_1);
- window.Font_Int(high_score_time.spheres[x1], 88.0f, y_position, 10.0f, R_7, G_7, B_7);
- window.Font_Char(high_score_time.name[x1], 145.0f, y_position, 10.0f, R_7, G_7, B_7);
- }
-
- y_position = y_position - 10.0f;
- }
- }
-
- /***************************************************************************/
-
- void Sort_High_Score_Sphere()
-
- {
- High_Score_Struct temp;
- int sorted_index[6];
- int x1;
-
- // Initialize temp and sorted_index;
- temp = high_score_sphere;
- for (x1=0;x1<6;x1=x1+1)
- sorted_index[x1] = x1;
-
- // Add the new score to position [5]
- strncpy(high_score_sphere.name[5], high_score_name, 20);
- high_score_sphere.new_high[5] = true;
- high_score_sphere.spheres[5] = (int)(paddle_object[Compete].score);
- high_score_sphere.time[5] = paddle_object[Compete].time_lapse_score;
-
- // Sort indexes
- qsort(sorted_index, 6, sizeof(int), Compare_High_Score_Sphere);
-
- // Copy the sorted values to temp
- for (x1=0;x1<6;x1=x1+1)
- {
- strncpy(temp.name[x1], high_score_sphere.name[sorted_index[x1]], 15);
- temp.new_high[x1] = high_score_sphere.new_high[sorted_index[x1]];
- temp.spheres[x1] = high_score_sphere.spheres[sorted_index[x1]];
- temp.time[x1] = high_score_sphere.time[sorted_index[x1]];
- temp.name[x1][15] = '\0';
- }
-
- // Copy the sorted values back
- high_score_sphere = temp;
- }
-
- /***************************************************************************/
-
- void Sort_High_Score_Time()
-
- {
- High_Score_Struct temp;
- int sorted_index[6];
- int x1;
-
- // Initialize temp and sorted_index;
- temp = high_score_time;
- for (x1=0;x1<6;x1=x1+1)
- sorted_index[x1] = x1;
-
- // Add the new score to position [5]
- strncpy(high_score_time.name[5], high_score_name, 20);
- high_score_time.new_high[5] = true;
- high_score_time.spheres[5] = (int)(paddle_object[Compete].score);
- high_score_time.time[5] = paddle_object[Compete].time_lapse_score;
-
- // Sort indexes
- qsort(sorted_index, 6, sizeof(int), Compare_High_Score_Time);
-
- // Copy the sorted values to temp
- for (x1=0;x1<6;x1=x1+1)
- {
- strncpy(temp.name[x1], high_score_time.name[sorted_index[x1]], 15);
- temp.new_high[x1] = high_score_time.new_high[sorted_index[x1]];
- temp.spheres[x1] = high_score_time.spheres[sorted_index[x1]];
- temp.time[x1] = high_score_time.time[sorted_index[x1]];
- temp.name[x1][15] = '\0';
- }
-
- // Copy the sorted values back
- high_score_time = temp;
- }
-
- /***************************************************************************/